
//
//  HomeSearchView.m
//  BusinessMarket
//
//  Created by Michael Li on 2018/11/13.
//  Copyright © 2018年 Michael Li. All rights reserved.
//

#import "HomeSearchHeadView.h"
@interface HomeSearchHeadView()<UITextFieldDelegate>
@property(nonatomic,strong) UIButton *msgBtn;

@end
@implementation HomeSearchHeadView

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
//        self.backgroundColor = [UIColor redColor];
        self.tf = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, kWidth, kHeight)];
        [self addSubview:self.tf];
        [self.tf addTarget:self action:@selector(tfChange:) forControlEvents:UIControlEventEditingChanged];
        self.tf.delegate = self;
        self.tf.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:0.8];
        self.tf.placeholder = @"输入您要搜索的内容";
//        self.tf.tintColor = [UIColor grayColor];
        self.tf.font = [UIFont systemFontOfSize:14];
        self.tf.tintColor = kOrangeBg;
        self.tf.returnKeyType = UIReturnKeySearch;
        self.tf.delegate = self;
        self.tf.layer.cornerRadius = 3;
        self.tf.layer.masksToBounds = YES;
//        <#self#>.layer.borderColor  = <#[UIColor whiteColor]#>.CGColor;
//        <#self#>.layer.borderWidth  = <#2#>;

        self.tf.clearButtonMode = UITextFieldViewModeWhileEditing;
//        [self.tf addTarget:self action:@selector(clickTF) forControlEvents:UIControlEventEditingChanged];

        
        UIImageView *iv = [[UIImageView alloc]initWithFrame:CGRectMake(10, (kHeight-32/2)/2, 32/2, 32/2)];
        iv.image = [UIImage imageNamed:@"icon_18"];
        [self.tf addSubview:iv];
        self.tf.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 40, 0)];
//        iv.backgroundColor = kOrangeBg;
        self.tf.leftViewMode = UITextFieldViewModeAlways;
    }
    return self;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (self.returnValueSearcBlock) {
        self.returnValueSearcBlock(2, self.tf.text);
    };
    NSLog(@"点击了搜索");
    return YES;
}
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    XLog(@"textFieldShouldBeginEditing");
    return YES;
}
-(void)tfChange:(UITextField *)tfChange
{
    NSLog(@"tfChange:%@",tfChange);
    if ([self.delegate respondsToSelector:@selector(homeSearchHeadView:withTFChange:)]) {
        [self.delegate homeSearchHeadView:self withTFChange:tfChange];
    }
}
@end
